package com.erp.module.gongGao

import android.content.Context
import com.erp.bean.GonggaoBean
import com.erp.bean.Twostringbean
import com.erp.Interface.OnUserDataInterface
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

/**
 * Created by Administrator on 2019/3/18/018.
 * 作者：刘洋
 */
class IGongGaoP(var list : MutableList<GonggaoBean>, var context : Context, var V : GongGaoContract.GongGaoView): BasePullP(),GongGaoContract.GongGaoP {
    val md : GongGaoContract.GongGaoMP= GongGaoModel()
    var searchParams: MutableList<Twostringbean> = ArrayList()
    init {
        PullV=V
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        md.getGongGaoData(context,page,pagesize,searchParams,onUserDataInterface)
    }

    override fun jsondata(data: String?) {
        if (data==null){
            return
        }
        try {
            val js = JSONArray(data)
            for (i in 0 until js.length()) {
                val gonggaoBean = GonggaoBean()
                val jo = js.get(i) as JSONObject
                gonggaoBean.title = JsonUtil.getvolue(jo, "title")
                gonggaoBean.nid = JsonUtil.getvolue(jo, "nid")
                gonggaoBean.changed = JsonUtil.getvolue(jo, "changed")
                gonggaoBean.type = JsonUtil.getvolue(jo, "type")
                gonggaoBean.field_notice_board_time_value = JsonUtil.getvolue(jo, "field_notice_board_time_value")
                gonggaoBean.type_name = JsonUtil.getvolue(jo, "type_name")
                list.add(gonggaoBean)
            }
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    override fun listClean() {
        list.clear()
    }

    override fun sousuo(searchParams: MutableList<Twostringbean>) {
        this.searchParams=searchParams
        xiala()
    }
}